package com.itheima.health.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.health.constants.MessageConstant;
import com.itheima.health.dao.MemberDao;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Member;
import com.itheima.health.service.LoginMobileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.Map;

/**
 * 登录实现类
 */
@Service(interfaceClass = LoginMobileService.class)
@Transactional
public class LoginMobileServiceImpl implements LoginMobileService {


    @Autowired
    private MemberDao memberDao;
    /**
     * 用户登录
     * @param map
     * @return
     */
    @Override
    public Result login(Map map) {
        // 用户是否为新用户
        String telephone = (String) map.get("telephone");
        Member member = memberDao.isMember(map);
        // 用户不存在,添加用户
        if (member == null) {
            member = new Member();
            member.setPhoneNumber(telephone);
            member.setRegTime(new Date());
            memberDao.addMember(member);
        }
        // 返回登录成功
        return new Result(true, MessageConstant.LOGIN_SUCCESS);

    }
}
